package com.recipedb.recipedb.controller;

import com.recipedb.recipedb.entity.RecipeCommentLike;
import com.recipedb.recipedb.entity.RecipeCommentLikeId;
import com.recipedb.recipedb.service.RecipeCommentLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/recipecommentlike")
public class RecipeCommentLikeController {

    @Autowired
    private RecipeCommentLikeService service;

    @PostMapping
    public RecipeCommentLike add(@RequestBody RecipeCommentLike entity) {
        return service.save(entity);
    }

    @DeleteMapping
    public void delete(@RequestBody RecipeCommentLikeId id) {
        service.deleteById(id);
    }

    @GetMapping("/single")
    public Optional<RecipeCommentLike> get(@RequestBody RecipeCommentLikeId id) {
        return service.findById(id);
    }

    @GetMapping("/all")
    public List<RecipeCommentLike> getAll() {
        return service.findAll();
    }

    // 根据评论ID查询所有点赞记录
    @GetMapping("/by-comment")
    public List<RecipeCommentLike> getLikesByCommentId(@RequestParam Long commentId) {
        return service.findByCommentId(commentId);
    }

}
